   subroutine pyscfio_split(filename2, dsetname2, icore, nfirst, nread, nmo2) 

     USE HDF5 ! This module contains all necessary modules

     IMPLICIT NONE

     integer, intent(in) :: nfirst, nread, nmo2
!
! I don't know why, but LEN=4 and LEN=6 is necessary here! Fan Wang
!
     CHARACTER(LEN=4), intent(inout) :: filename2 ! File name
     CHARACTER(LEN=6), intent(inout) :: dsetname2  ! Dataset name

     INTEGER(HID_T) :: file_id       ! File identifier
     INTEGER(HID_T) :: dset_id       ! Dataset identifier
     INTEGER(HID_T) :: dataspace     ! Dataspace identifier
     INTEGER(HID_T) :: memspace      ! memspace identifier

     INTEGER(HSIZE_T), DIMENSION(2) :: dimsm  ! Dataset dimensions
                                              ! in memory
     INTEGER(HSIZE_T), DIMENSION(2) :: dimsf ! Dataset dimensions.
     INTEGER(HSIZE_T), DIMENSION(2) :: max_dims ! Dataset dimensions.

     INTEGER(HSIZE_T), DIMENSION(2) :: count 
                                            ! Size of the hyperslab in the file
     INTEGER(HSIZE_T), DIMENSION(2) :: offset 
                                            !hyperslab offset in the file
     INTEGER(HSIZE_T), DIMENSION(2) :: count_out 
                                            !Size of the hyperslab in memory
     INTEGER(HSIZE_T), DIMENSION(2) :: offset_out
                                            !hyperslab offset in memory
     INTEGER(HSIZE_T), DIMENSION(1) :: count_out2 
                                            !Size of the hyperslab in memory
     INTEGER(HSIZE_T), DIMENSION(1) :: offset_out2
                                            !hyperslab offset in memory
     INTEGER*4 :: dsetrank = 1 ! Dataset rank ( in file )
     INTEGER*4 :: memrank = 2  ! Dataset rank ( in memory )
     INTEGER :: i, j, k, nmo2

     INTEGER*4 :: error  ! Error flag
     INTEGER(HSIZE_T), DIMENSION(3) :: data_dims
     INTEGER(HSIZE_T), DIMENSION(1) :: data_dims2 
     real*8, intent(inout) :: icore(nmo2,nread)
     real*8, external :: dnrm2
     real*8 tt1 , tt2

     !
     ! Write data to the HDF5 file.
     !

     !
     ! Initialize FORTRAN interface.
     !
     call cpu_time(tt1)
     CALL h5open_f(error)

  ! This  part of the code reads the hyperslab from the sds.h5 file just
  ! created, into a 2-dimensional plane of the 3-dimensional dataset.
  !
!---------------------------------------
     CALL h5fopen_f (filename2, H5F_ACC_RDWR_F, file_id, error)

     CALL h5dopen_f(file_id, dsetname2, dset_id, error)

     CALL h5dget_space_f(dset_id, dataspace, error)

     CALL h5sget_simple_extent_dims_f(dataspace,data_dims, max_dims, error)

!     CALL h5dread_f(dset_id, H5T_NATIVE_DOUBLE, icore, data_dims,error)
   
!     nmo2 = nmo*(nmo+1)/2
!     nmo2 = nmo*nmo
     count = (/nmo2, nread/)
     offset = (/0,nfirst-1/)
     CALL h5sselect_hyperslab_f(dataspace, H5S_SELECT_SET_F, &
                                 offset, count, error)
!    count_out = (/nmo2*nread/)
!    offset_out = (/(nfirst-2)*nmo2+1/)
!    CALL h5sselect_hyperslab_f(dataspace, H5S_SELECT_SET_F, &
!                                offset_out, count_out, error)

     dimsm = (/nmo2,nread/)
     CALL h5screate_simple_f(memrank, dimsm, memspace, error)

     count_out = (/nmo2,nread/)
     offset_out = (/0,0/)
     CALL h5sselect_hyperslab_f(memspace, H5S_SELECT_SET_F, &
                                offset_out, count_out, error)
     call cpu_time(tt2)
!     write(6,*)'time for prepare', tt2-tt1
     call cpu_time(tt1)
     data_dims(1) = nmo2
     data_dims(2) = nread 
!     CALL H5dread_f(dset_id, H5T_NATIVE_DOUBLE, icore, data_dims, error)
!    CALL H5dread_f(dset_id, H5T_NATIVE_DOUBLE, icore, data_dims, error, &
!                    H5S_ALL_F, dataspace)
!    write(6,*)'norm of icore 1', H5S_ALL_F,  dnrm2(nmo2*nread, icore, 1)
     CALL H5dread_f(dset_id, H5T_NATIVE_DOUBLE, icore, data_dims, error, &
                    memspace, dataspace)
!    write(6,*)'norm of icore 2', memspace, dnrm2(nmo2*nread, icore, 1)
     call cpu_time(tt2)
!     write(6,*)'time for read   ', tt2-tt1
     !
     ! Close the dataspace for the dataset.
     !
     CALL h5sclose_f(dataspace, error)

     !
     ! Close the memoryspace.
     !
!
     CALL h5sclose_f(memspace, error)

     !
     ! Close the dataset.
     !
     CALL h5dclose_f(dset_id, error)

     !
     ! Close the file.
     !
     CALL h5fclose_f(file_id, error)

     !
     ! Close FORTRAN interface.
     !
     CALL h5close_f(error)

     END 
